package com.mmlc.meimei.lichengkongjian.Adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.mmlc.meimei.lichengkongjian.R;
import com.mmlc.network.responsebean.ShopOrderPayTypeResponseBean;
import com.mmlc.utils.ViewUtils;

import java.util.List;

/**
 * Created by Administrator on 2016/10/20 0020.
 */
public class PayTypeAdapter extends BaseAdapter{

    private String pay_type;

    private List<ShopOrderPayTypeResponseBean.DataBean> data;

    private Context context;

    public String getPay_type() {
        return pay_type;
    }

    public void setPay_type(String pay_type) {
        this.pay_type = pay_type;
    }

    public PayTypeAdapter(List<ShopOrderPayTypeResponseBean.DataBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public ShopOrderPayTypeResponseBean.DataBean getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    public List<ShopOrderPayTypeResponseBean.DataBean> getData() {
        return data;
    }

    public void setData(List<ShopOrderPayTypeResponseBean.DataBean> data) {
        this.data = data;
    }

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }

    public ShopOrderPayTypeResponseBean.DataBean checkBean;
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView==null)
        {
            convertView= LayoutInflater.from(getContext()).inflate(R.layout.item_pay_type,parent,false);
        }
        TextView name= ViewUtils.getView(convertView, R.id.tv_pay_type);
        CheckBox checkBox=ViewUtils.getView(convertView,R.id.cb_check);
        name.setText(getItem(position).getPay_name());
        if (TextUtils.equals(getItem(position).getPay_code(),pay_type))
        {
            checkBox.setChecked(true);
        }
        else
        {
            checkBox.setChecked(false);
        }
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!TextUtils.equals(getItem(position).getPay_code(),pay_type))
                {
                    checkBean = getItem(position);
                    pay_type=getItem(position).getPay_code();
                    notifyDataSetChanged();
                }

            }
        });
        return convertView;
    }
}
